//
//  XLAnchorWorkVC.m
//  XiangLove
//
//  Created by 李传坤 on 2018/7/31.
//  Copyright © 2018年 BAOMIHUA.COM. All rights reserved.
//

#import "XLAnchorWorkVC.h"

#import "XLAnchorWorkTopCell.h"
#import "XLHTTPSessionManager.h"
#import "XLAccountManager.h"
#import <ReactiveCocoa.h>

#import "XLTaskViewController.h"
#import "BMHCashOutViewController.h"
#import "XLIncomeRecordBaseVC.h"
#import "BMHCashOutAuthorizeViewController.h"
#import "XLAnchorEvaluateVC.h"

@interface XLAnchorWorkVC ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,strong) UITableView    *tableView;
@property (nonatomic,strong) NSMutableArray *modelArray;
@property (nonatomic,strong) NSDictionary *dicData;
@property (nonatomic,copy  ) NSString            *page;
@property (nonatomic,strong) UIButton       *charmBtn;
@end

@implementation XLAnchorWorkVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self showBackButton:NULL];
    if (@available(iOS 11.0, *)) {
        _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    } else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    [self addTableView];
    _page = @"1";
    [self requrstTalkedPeoplePage];
}

-(void)requrstTalkedPeoplePage
{
    NSDictionary *dic = @{@"pageIndex":_page,
                          @"pageSize":@"16",
                          @"userId":[[XLAccountManager shareInstance]model].Id,
                          @"type":@"1"
                          };
    @weakify(self)
    [[[XLHTTPSessionManager sharedManager]XLV2GET:@"/Api/v2/AnchorDest/GetAnchorDeskInfo" parameters:dic resultClass:nil] subscribeNext:^(id x) {
        @strongify(self)
        _dicData = x;
        [_tableView reloadData];
    } error:^(NSError *error) {
        NSLog(@"%@", error);
        
    }];
    
}
-(void)addTableView
{
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0,0, XQScreenW, XQScreenH-49) style:UITableViewStylePlain];
    _tableView.rowHeight = 86;self.tableView.sectionHeaderHeight = 10;
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    _tableView.backgroundColor = [UIColor whiteColor];
    _tableView.separatorColor = [UIColor groupTableViewBackgroundColor];
    [_tableView setTableFooterView:[[UIView alloc] initWithFrame:CGRectZero]];
//    [_tableView registerClass:[XLAnchorWorkTopCell class] forCellReuseIdentifier:NSStringFromClass([XLAnchorWorkTopCell class])];
    [self.view addSubview:_tableView];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
//    if (indexPath.section == 0 && indexPath.row == 0) {
//        return 0.1;
//    }
    return 44;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0){
        return 3;
    }
    return 2;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//    if (indexPath.section == 0){
//        if (indexPath.row == 0){
//            XLAnchorWorkTopCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XLAnchorWorkTopCell class]) forIndexPath:indexPath];
//            cell.selectionStyle = UITableViewCellSelectionStyleNone;
//            if (![[_dicData objectForKey:@"TotalMoney"]isKindOfClass:[NSNull class]] && ![_dicData isKindOfClass:[NSNull class]]){
//                CGFloat number = [[_dicData objectForKey:@"TotalMoney"] floatValue];
//                 cell.CashNumber.text = [NSString stringWithFormat:@"¥%.2f",number];
//            }
//            return  cell;
//        }
//    }
    static NSString * showUserInfoCellIdentifier = @"ShowUserInfoCell";
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:showUserInfoCellIdentifier];
    if (cell == nil){
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:NSStringFromClass([UITableViewCell class])];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.detailTextLabel.font = [UIFont systemFontOfSize:16];
    cell.detailTextLabel.textColor = kLightGrayColor;
    cell.textLabel.font = [UIFont systemFontOfSize:16];
    cell.textLabel.textColor = kBlackColor;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.backgroundColor = kWhiteColor;
    if (indexPath.section == 0){
        if (indexPath.row == 0){
            cell.textLabel.text= @"收入详情";
        }
        if (indexPath.row == 1){
            cell.textLabel.text= @"任务奖励";
        }
        if (indexPath.row == 2){
            cell.textLabel.text= @"服务评价";
        }
    }
    if (indexPath.section == 1){
        if (indexPath.row == 0){
            if (![[_dicData objectForKey:@"LiveChatPrice"] isKindOfClass:[NSNull class]]){
                cell.detailTextLabel.text = [NSString stringWithFormat:@"%@0金豆/分钟",[_dicData objectForKey:@"LiveChatPrice"]];
                if ([[[NSUserDefaults standardUserDefaults] objectForKey:XiangLove_IsSH] boolValue]) {//
                    cell.detailTextLabel.hidden = YES;
                }
            }
            cell.accessoryType = UITableViewCellAccessoryNone;
            cell.textLabel.text= @"视频价格";
        }
        if (indexPath.row == 1){
            if ([[_dicData objectForKey:@"ContractStatus"] integerValue] == 1) {
                cell.detailTextLabel.text = @"审核中";

            }
            if ([[_dicData objectForKey:@"ContractStatus"]integerValue] == 2) {
                cell.detailTextLabel.text = @"已认证";

            }
            if ([[_dicData objectForKey:@"ContractStatus"]integerValue] == 3) {
                cell.detailTextLabel.text = @"未认证";

            }
            cell.textLabel.text= @"实名认证";
        }
    }
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0){//收入详情
        
        if (indexPath.row == 0){
            XLIncomeRecordBaseVC *vc = [[XLIncomeRecordBaseVC alloc] init];
            [self.navigationController pushViewController:vc animated:YES];
        }
        if (indexPath.row == 1){//任务奖励
            XLTaskViewController *vc = [[XLTaskViewController alloc] init];
            [self.navigationController pushViewController:vc animated:YES];
        }
        if (indexPath.row == 2){//服务评价
            XLAnchorEvaluateVC *vc = [[XLAnchorEvaluateVC alloc]init];
            [self.navigationController pushViewController:vc animated:YES];
        }
        
    }
    if (indexPath.section == 1){
        if (indexPath.row == 0){
            
        }
        if (indexPath.row == 1){//去认证
             if ([[_dicData objectForKey:@"ContractStatus"]integerValue] == 3) {
                BMHCashOutAuthorizeViewController *vc = [[BMHCashOutAuthorizeViewController alloc] init];
                [self.navigationController pushViewController:vc animated:YES];
             }
        }
    }
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        return 0;
    }
    return 10;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end

